package com.xxx.client.android.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xxx.client.android.R;
import com.xxx.client.android.api.ArticleVO;

/**
 * Adapter representing articles
 * 
 */
public class ArticleAdapter extends ArrayListAdapter<ArticleVO> {

	public ArticleAdapter(Activity context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;

		ViewHolder holder;

		if (row == null) {
			LayoutInflater inflater = mContext.getLayoutInflater();
			row = inflater.inflate(R.layout.article_row, null);

			holder = new ViewHolder();
			holder.titleName = (TextView) row
					.findViewById(R.id.ArticleRowRowTextView);

			row.setTag(holder);
		} else {
			holder = (ViewHolder) row.getTag();
		}

		holder.titleName.setText(mList.get(position).getTitleName());

		return row;
	}

	/**
	 * Class implementing holder pattern, performance boost
	 */
	static class ViewHolder {
		TextView titleName;
	}
}
